﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace MIPS_Simulator
{
    class Registers
    {
        private const short maxRegNum = 32;
        Dictionary<short, long> registers;
        
        private bool regWrite;
        public bool RegWrite
        {
            set
            {
                regWrite = value;
            }
        }
        public Registers()
        {
            registers = new Dictionary<short, long>();
        }

        public void StoreReg(long data, short location)
        {
            if (regWrite == false)
                throw new WriteNotEnabledException();

            if (location > maxRegNum || location < 0)
                throw new IndexOutOfRangeException("Register index of of range");
            try
            {
                registers.Add(location, data);
            }
            catch (ArgumentException e)
            {
                registers[location] = data;
            }

        }

        public long loadReg(short location) 
        {
            long value;
            if (location > maxRegNum || location < 0)
                throw new IndexOutOfRangeException("Memory index of of range");

            registers.TryGetValue(location, out value);
            return value;

        }
    }
}
